/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pa165.dominating.species.entities;

import java.io.Serializable;
import javax.persistence.*;
import pa165.dominating.species.dao.PersistObject;
import pa165.dominating.species.enums.UserType;

/**
 *
 * @author Ondrej Prazak
 */
@Entity
@Table(name = "person")  //The entity table name (user) is a reserved SQL keyword
@NamedQueries(
        @NamedQuery(name = "getAllUsers", query = "select u from User u"))
public class User implements Serializable, PersistObject {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(nullable = false)
    private String Name;
    @Column(nullable = false, unique = true)
    private String login;
    @Column(nullable = false)
    private String password;
    @Column(nullable = false)
    @Enumerated(EnumType.STRING)
    private UserType type;

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final User usr = (User) obj;
        if (this.getId() != usr.getId() && (this.getId() == null || !this.getId().equals(usr.getId()))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        return getName().hashCode() * 17 + getPassword().hashCode() * 23;
    }

    public void setId(final Long id) {
        this.id = id;
    }

    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public Long getId() {
        return id;
    }

    public UserType getType() {
        return type;
    }

    public void setType(UserType type) {
        this.type = type;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    @Override
    public String toString() {
        return "pa165.dominatingspecies.User[ id = " + getId() + ", name = " + getName() + " ]";
    }
}
